<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    #box{
        width:200px;
        height: 200px;
        background-color: #0f0;
        position: absolute;
        top:0;
        left: 0;
    }
    </style>
</head>
<body>
    <div id="box"></div>
    <script>
    var vox=document.getElementById("box");
    document.onkeydown=function(e){
        // alert(e.keyCode);
        switch (e.keyCode){
            case 37:
                box.style.left=box.offsetLeft-10+"px";
            break;
            
            case 39:
                box.style.left=box.offsetLeft+10+"px";
            break;

            case 38:
                box.style.top=box.offsetTop-10+"px";
            break;
            
            case 40:
                box.style.top=box.offsetTop+10+"px";
            break;

        }
    }
    </script>
</body>
</html>